package org.pine.swagger;

import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @ClassName UserController
 * @Description Swagger API接口测试
 * @Author liucs
 * @Date 2021-02-20
 * @Version V1.0
 */
@RestController
@Api(tags = "用户数据接口")
public class UserController {
    @ApiOperation(value = "查询用户",notes = "根据ID查询用户")
    @ApiImplicitParam(paramType="path",name = "id",value = "用户id",required = true)
    @GetMapping("/user/{id}")
    public String getUserById(@PathVariable Integer id){
        return "/user/"+id;
    }

    @ApiResponses({
            @ApiResponse(code = 200,message = "删除成功！"),
            @ApiResponse(code = 500,message = "删除失败！")
    })
    @ApiOperation(value = "删除用户",notes = "通过ID删除用户")
    @DeleteMapping("/user/{id}")
    public Integer deleteUserById(@PathVariable Integer id){
        return id;
    }

    @ApiOperation(value = "添加用户",notes = "添加一个用户，传入用户名和地址")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(paramType = "query",name = "username",value = "用户名",required = true,defaultValue = "madder"),
                    @ApiImplicitParam(paramType = "query",name = "address",value = "地址",required = true,defaultValue = "zhengzhou")
            }
    )
    @PostMapping("/user")
    public String addUser(@RequestParam String username,@RequestParam String address){
        return username+":"+address;
    }

    @ApiOperation(value = "修改用户",notes = "修改用户，传入用户信息")
    @PutMapping("/user")
    public String updateUser(@RequestBody User user){
        return user.toString();
    }

    /**
     * 不对该接口方法生成文档
     */
    @GetMapping("/ingore")
    @ApiIgnore
    public void ingoreMethod(){

    }

}
